package LeetCode.leetcode437;

import java.util.List;

class Solution {
    public int pathSum(TreeNode root, int targetSum) {
        if (root == null) return 0;
        int res = 0;
        res += dfs(root, targetSum);
        res += pathSum(root.left, targetSum);
        res += pathSum(root.right, targetSum);
        return res;
    }
    public int dfs(TreeNode root, long targetSum) {
        if (root == null) return 0;
        int res = 0;
        if (root.val == targetSum) {
            res++;
        }
        res += dfs(root.left, targetSum - root.val);
        res += dfs(root.right, targetSum - root.val);
        return res;
    }
}